package com.woniuxy.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * @BelongsProject: pigTrotterStore
 * @BelongsPackage: com.woniuxy.util
 * @Author: Quan
 * @Date: 2025/3/13 19:39
 */
public class GetUserIdFromToken {
	public static Integer getUserId() throws ParseException {
		ServletRequestAttributes servletRequestAttributes =
				(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = servletRequestAttributes.getRequest();

		String token = request.getHeader("token");

		return JWTUtil.getUserId(token);
	}
}
